let name = document.querySelector('.nameBox>.name');
let time = document.querySelector('.time');
let erweima = document.querySelector('.erweima');
let button1 = document.querySelector(".btn1");
let button2 = document.querySelector(".btn2");
console.log(button1);


let token = sessionStorage.getItem('token');
let show_name = sessionStorage.getItem('show_name');
console.log(show_name); //预约具体时间
console.log(token);

let url = 'http://newshopapi.0melon0.cn/api/f_user/bookday';
let data = {
    "token": token,
    "day_time": sessionStorage.getItem("day_time"),
    "show_id": sessionStorage.getItem("show_id"),
    "show_name": sessionStorage.getItem("show_name")
}

//请求数据,姓名和到场时间
ajax(url, data, "POST").then(res => {
    console.log(res.result);
    name.innerHTML = `<p class="name">您好，${res.result.name}</p>`
    time.innerHTML = `<span class="time">欢迎您在${res.result.day_time}&nbsp${show_name}参观2019广州国际花卉艺术展暨中国插花花艺展。</span>`


    //请求数据，二维码
    let url = 'http://newshopapi.0melon0.cn/api/f_user/Qrcode';
    let data = {
        "token": sessionStorage.getItem("token"),
        "id": res.result.id
    };
    return ajax(url, data, 'GET')
}).then(res => {
    console.log(res.data.data);
    erweima.innerHTML = ` <img src="${res.data.data}" alt="">`;


    // 通过button按钮保存二维码
    button1.addEventListener("click", () => {
        console.log(123);
        let img = erweima.querySelector("img"); // 获取要下载的图片
        var url = img.src; // 获取图片地址
        var a = document.createElement('a'); // 创建一个a节点插入的document
        var event = new MouseEvent('click') // 模拟鼠标click点击事件
        a.download = '保存二维码' // 设置a节点的download属性值
        a.href = url; // 将图片的src赋值给a节点的href
        a.dispatchEvent(event) // 触发鼠标点击事件
    });

    //返回首页
    button2.addEventListener('click', () => {
        location.href = "1login.html";
        // sessionStorage.setItem("show_id", show_id);
        sessionStorage.setItem("show_name", show_name);
        console.log(sessionStorage.setItem("show_name", show_name));
    })

})